<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商户Id(0为总后台管理员创建,不为0的时候是商户后台创建)" prop="merId">
        <el-input
          v-model="queryParams.merId"
          placeholder="请输入商户Id(0为总后台管理员创建,不为0的时候是商户后台创建)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品名称" prop="storeName">
        <el-input
          v-model="queryParams.storeName"
          placeholder="请输入商品名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品简介" prop="storeInfo">
        <el-input
          v-model="queryParams.storeInfo"
          placeholder="请输入商品简介"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="关键字" prop="keyword">
        <el-input
          v-model="queryParams.keyword"
          placeholder="请输入关键字"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品条码" prop="barCode">
        <el-input
          v-model="queryParams.barCode"
          placeholder="请输入商品条码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分类id" prop="cateId">
        <el-input
          v-model="queryParams.cateId"
          placeholder="请输入分类id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品价格" prop="price">
        <el-input
          v-model="queryParams.price"
          placeholder="请输入商品价格"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会员价格" prop="vipPrice">
        <el-input
          v-model="queryParams.vipPrice"
          placeholder="请输入会员价格"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市场价" prop="otPrice">
        <el-input
          v-model="queryParams.otPrice"
          placeholder="请输入市场价"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮费" prop="postage">
        <el-input
          v-model="queryParams.postage"
          placeholder="请输入邮费"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位名" prop="unitName">
        <el-input
          v-model="queryParams.unitName"
          placeholder="请输入单位名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="排序" prop="sort">
        <el-input
          v-model="queryParams.sort"
          placeholder="请输入排序"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销量" prop="sales">
        <el-input
          v-model="queryParams.sales"
          placeholder="请输入销量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库存" prop="stock">
        <el-input
          v-model="queryParams.stock"
          placeholder="请输入库存"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="isShow">
        <el-input
          v-model="queryParams.isShow"
          placeholder="请输入状态"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否热卖" prop="isHot">
        <el-input
          v-model="queryParams.isHot"
          placeholder="请输入是否热卖"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否优惠" prop="isBenefit">
        <el-input
          v-model="queryParams.isBenefit"
          placeholder="请输入是否优惠"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否精品" prop="isBest">
        <el-input
          v-model="queryParams.isBest"
          placeholder="请输入是否精品"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否新品" prop="isNew">
        <el-input
          v-model="queryParams.isNew"
          placeholder="请输入是否新品"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="添加时间" prop="addTime">
        <el-input
          v-model="queryParams.addTime"
          placeholder="请输入添加时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否包邮" prop="isPostage">
        <el-input
          v-model="queryParams.isPostage"
          placeholder="请输入是否包邮"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否删除" prop="isDel">
        <el-input
          v-model="queryParams.isDel"
          placeholder="请输入是否删除"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商户是否代理 0不可代理1可代理" prop="merUse">
        <el-input
          v-model="queryParams.merUse"
          placeholder="请输入商户是否代理 0不可代理1可代理"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="获得积分" prop="giveIntegral">
        <el-input
          v-model="queryParams.giveIntegral"
          placeholder="请输入获得积分"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="成本价" prop="cost">
        <el-input
          v-model="queryParams.cost"
          placeholder="请输入成本价"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="秒杀状态 0 未开启 1已开启" prop="isSeckill">
        <el-input
          v-model="queryParams.isSeckill"
          placeholder="请输入秒杀状态 0 未开启 1已开启"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="砍价状态 0未开启 1开启" prop="isBargain">
        <el-input
          v-model="queryParams.isBargain"
          placeholder="请输入砍价状态 0未开启 1开启"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否优品推荐" prop="isGood">
        <el-input
          v-model="queryParams.isGood"
          placeholder="请输入是否优品推荐"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否单独分佣" prop="isSub">
        <el-input
          v-model="queryParams.isSub"
          placeholder="请输入是否单独分佣"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="虚拟销量" prop="ficti">
        <el-input
          v-model="queryParams.ficti"
          placeholder="请输入虚拟销量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="浏览量" prop="browse">
        <el-input
          v-model="queryParams.browse"
          placeholder="请输入浏览量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品二维码地址(用户小程序海报)" prop="codePath">
        <el-input
          v-model="queryParams.codePath"
          placeholder="请输入商品二维码地址(用户小程序海报)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="淘宝京东1688类型" prop="soureLink">
        <el-input
          v-model="queryParams.soureLink"
          placeholder="请输入淘宝京东1688类型"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主图视频链接" prop="videoLink">
        <el-input
          v-model="queryParams.videoLink"
          placeholder="请输入主图视频链接"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="运费模板ID" prop="tempId">
        <el-input
          v-model="queryParams.tempId"
          placeholder="请输入运费模板ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="规格 0单 1多" prop="specType">
        <el-select v-model="queryParams.specType" placeholder="请选择规格 0单 1多" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="活动显示排序0=默认, 1=秒杀，2=砍价，3=拼团" prop="activity">
        <el-input
          v-model="queryParams.activity"
          placeholder="请输入活动显示排序0=默认, 1=秒杀，2=砍价，3=拼团"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['store:product:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['store:product:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['store:product:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['store:product:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="productList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="商品id" align="center" prop="id" v-if="false"/>
      <el-table-column label="商户Id(0为总后台管理员创建,不为0的时候是商户后台创建)" align="center" prop="merId" />
      <el-table-column label="商品图片" align="center" prop="image" />
      <el-table-column label="轮播图" align="center" prop="sliderImage" />
      <el-table-column label="商品名称" align="center" prop="storeName" />
      <el-table-column label="商品简介" align="center" prop="storeInfo" />
      <el-table-column label="关键字" align="center" prop="keyword" />
      <el-table-column label="商品条码" align="center" prop="barCode" />
      <el-table-column label="分类id" align="center" prop="cateId" />
      <el-table-column label="商品价格" align="center" prop="price" />
      <el-table-column label="会员价格" align="center" prop="vipPrice" />
      <el-table-column label="市场价" align="center" prop="otPrice" />
      <el-table-column label="邮费" align="center" prop="postage" />
      <el-table-column label="单位名" align="center" prop="unitName" />
      <el-table-column label="排序" align="center" prop="sort" />
      <el-table-column label="销量" align="center" prop="sales" />
      <el-table-column label="库存" align="center" prop="stock" />
      <el-table-column label="状态" align="center" prop="isShow" />
      <el-table-column label="是否热卖" align="center" prop="isHot" />
      <el-table-column label="是否优惠" align="center" prop="isBenefit" />
      <el-table-column label="是否精品" align="center" prop="isBest" />
      <el-table-column label="是否新品" align="center" prop="isNew" />
      <el-table-column label="添加时间" align="center" prop="addTime" />
      <el-table-column label="是否包邮" align="center" prop="isPostage" />
      <el-table-column label="是否删除" align="center" prop="isDel" />
      <el-table-column label="商户是否代理 0不可代理1可代理" align="center" prop="merUse" />
      <el-table-column label="获得积分" align="center" prop="giveIntegral" />
      <el-table-column label="成本价" align="center" prop="cost" />
      <el-table-column label="秒杀状态 0 未开启 1已开启" align="center" prop="isSeckill" />
      <el-table-column label="砍价状态 0未开启 1开启" align="center" prop="isBargain" />
      <el-table-column label="是否优品推荐" align="center" prop="isGood" />
      <el-table-column label="是否单独分佣" align="center" prop="isSub" />
      <el-table-column label="虚拟销量" align="center" prop="ficti" />
      <el-table-column label="浏览量" align="center" prop="browse" />
      <el-table-column label="商品二维码地址(用户小程序海报)" align="center" prop="codePath" />
      <el-table-column label="淘宝京东1688类型" align="center" prop="soureLink" />
      <el-table-column label="主图视频链接" align="center" prop="videoLink" />
      <el-table-column label="运费模板ID" align="center" prop="tempId" />
      <el-table-column label="规格 0单 1多" align="center" prop="specType" />
      <el-table-column label="活动显示排序0=默认, 1=秒杀，2=砍价，3=拼团" align="center" prop="activity" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['store:product:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['store:product:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商品管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="商户Id(0为总后台管理员创建,不为0的时候是商户后台创建)" prop="merId">
          <el-input v-model="form.merId" placeholder="请输入商户Id(0为总后台管理员创建,不为0的时候是商户后台创建)" />
        </el-form-item>
        <el-form-item label="商品图片">
          <imageUpload v-model="form.image"/>
        </el-form-item>
        <el-form-item label="轮播图">
          <imageUpload v-model="form.sliderImage"/>
        </el-form-item>
        <el-form-item label="商品名称" prop="storeName">
          <el-input v-model="form.storeName" placeholder="请输入商品名称" />
        </el-form-item>
        <el-form-item label="商品简介" prop="storeInfo">
          <el-input v-model="form.storeInfo" placeholder="请输入商品简介" />
        </el-form-item>
        <el-form-item label="关键字" prop="keyword">
          <el-input v-model="form.keyword" placeholder="请输入关键字" />
        </el-form-item>
        <el-form-item label="商品条码" prop="barCode">
          <el-input v-model="form.barCode" placeholder="请输入商品条码" />
        </el-form-item>
        <el-form-item label="分类id" prop="cateId">
          <el-input v-model="form.cateId" placeholder="请输入分类id" />
        </el-form-item>
        <el-form-item label="商品价格" prop="price">
          <el-input v-model="form.price" placeholder="请输入商品价格" />
        </el-form-item>
        <el-form-item label="会员价格" prop="vipPrice">
          <el-input v-model="form.vipPrice" placeholder="请输入会员价格" />
        </el-form-item>
        <el-form-item label="市场价" prop="otPrice">
          <el-input v-model="form.otPrice" placeholder="请输入市场价" />
        </el-form-item>
        <el-form-item label="邮费" prop="postage">
          <el-input v-model="form.postage" placeholder="请输入邮费" />
        </el-form-item>
        <el-form-item label="单位名" prop="unitName">
          <el-input v-model="form.unitName" placeholder="请输入单位名" />
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <el-input v-model="form.sort" placeholder="请输入排序" />
        </el-form-item>
        <el-form-item label="销量" prop="sales">
          <el-input v-model="form.sales" placeholder="请输入销量" />
        </el-form-item>
        <el-form-item label="库存" prop="stock">
          <el-input v-model="form.stock" placeholder="请输入库存" />
        </el-form-item>
        <el-form-item label="状态" prop="isShow">
          <el-input v-model="form.isShow" placeholder="请输入状态" />
        </el-form-item>
        <el-form-item label="是否热卖" prop="isHot">
          <el-input v-model="form.isHot" placeholder="请输入是否热卖" />
        </el-form-item>
        <el-form-item label="是否优惠" prop="isBenefit">
          <el-input v-model="form.isBenefit" placeholder="请输入是否优惠" />
        </el-form-item>
        <el-form-item label="是否精品" prop="isBest">
          <el-input v-model="form.isBest" placeholder="请输入是否精品" />
        </el-form-item>
        <el-form-item label="是否新品" prop="isNew">
          <el-input v-model="form.isNew" placeholder="请输入是否新品" />
        </el-form-item>
        <el-form-item label="添加时间" prop="addTime">
          <el-input v-model="form.addTime" placeholder="请输入添加时间" />
        </el-form-item>
        <el-form-item label="是否包邮" prop="isPostage">
          <el-input v-model="form.isPostage" placeholder="请输入是否包邮" />
        </el-form-item>
        <el-form-item label="是否删除" prop="isDel">
          <el-input v-model="form.isDel" placeholder="请输入是否删除" />
        </el-form-item>
        <el-form-item label="商户是否代理 0不可代理1可代理" prop="merUse">
          <el-input v-model="form.merUse" placeholder="请输入商户是否代理 0不可代理1可代理" />
        </el-form-item>
        <el-form-item label="获得积分" prop="giveIntegral">
          <el-input v-model="form.giveIntegral" placeholder="请输入获得积分" />
        </el-form-item>
        <el-form-item label="成本价" prop="cost">
          <el-input v-model="form.cost" placeholder="请输入成本价" />
        </el-form-item>
        <el-form-item label="秒杀状态 0 未开启 1已开启" prop="isSeckill">
          <el-input v-model="form.isSeckill" placeholder="请输入秒杀状态 0 未开启 1已开启" />
        </el-form-item>
        <el-form-item label="砍价状态 0未开启 1开启" prop="isBargain">
          <el-input v-model="form.isBargain" placeholder="请输入砍价状态 0未开启 1开启" />
        </el-form-item>
        <el-form-item label="是否优品推荐" prop="isGood">
          <el-input v-model="form.isGood" placeholder="请输入是否优品推荐" />
        </el-form-item>
        <el-form-item label="是否单独分佣" prop="isSub">
          <el-input v-model="form.isSub" placeholder="请输入是否单独分佣" />
        </el-form-item>
        <el-form-item label="虚拟销量" prop="ficti">
          <el-input v-model="form.ficti" placeholder="请输入虚拟销量" />
        </el-form-item>
        <el-form-item label="浏览量" prop="browse">
          <el-input v-model="form.browse" placeholder="请输入浏览量" />
        </el-form-item>
        <el-form-item label="商品二维码地址(用户小程序海报)" prop="codePath">
          <el-input v-model="form.codePath" placeholder="请输入商品二维码地址(用户小程序海报)" />
        </el-form-item>
        <el-form-item label="淘宝京东1688类型" prop="soureLink">
          <el-input v-model="form.soureLink" placeholder="请输入淘宝京东1688类型" />
        </el-form-item>
        <el-form-item label="主图视频链接" prop="videoLink">
          <el-input v-model="form.videoLink" placeholder="请输入主图视频链接" />
        </el-form-item>
        <el-form-item label="运费模板ID" prop="tempId">
          <el-input v-model="form.tempId" placeholder="请输入运费模板ID" />
        </el-form-item>
        <el-form-item label="规格 0单 1多" prop="specType">
          <el-select v-model="form.specType" placeholder="请选择规格 0单 1多">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="活动显示排序0=默认, 1=秒杀，2=砍价，3=拼团" prop="activity">
          <el-input v-model="form.activity" placeholder="请输入活动显示排序0=默认, 1=秒杀，2=砍价，3=拼团" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProduct, getProduct, delProduct, addProduct, updateProduct, exportProduct } from "@/api/store/product";
import ImageUpload from '@/components/ImageUpload';

export default {
  name: "Product",
  components: {
    ImageUpload,
  },
  data() {
    return {
	  //按钮loading
	  buttonLoading: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品管理表格数据
      productList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        merId: undefined,
        image: undefined,
        sliderImage: undefined,
        storeName: undefined,
        storeInfo: undefined,
        keyword: undefined,
        barCode: undefined,
        cateId: undefined,
        price: undefined,
        vipPrice: undefined,
        otPrice: undefined,
        postage: undefined,
        unitName: undefined,
        sort: undefined,
        sales: undefined,
        stock: undefined,
        isShow: undefined,
        isHot: undefined,
        isBenefit: undefined,
        isBest: undefined,
        isNew: undefined,
        addTime: undefined,
        isPostage: undefined,
        isDel: undefined,
        merUse: undefined,
        giveIntegral: undefined,
        cost: undefined,
        isSeckill: undefined,
        isBargain: undefined,
        isGood: undefined,
        isSub: undefined,
        ficti: undefined,
        browse: undefined,
        codePath: undefined,
        soureLink: undefined,
        videoLink: undefined,
        tempId: undefined,
        specType: undefined,
        activity: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        merId: [
          { required: true, message: "商户Id(0为总后台管理员创建,不为0的时候是商户后台创建)不能为空", trigger: "blur" }
        ],
        image: [
          { required: true, message: "商品图片不能为空", trigger: "blur" }
        ],
        sliderImage: [
          { required: true, message: "轮播图不能为空", trigger: "blur" }
        ],
        storeName: [
          { required: true, message: "商品名称不能为空", trigger: "blur" }
        ],
        storeInfo: [
          { required: true, message: "商品简介不能为空", trigger: "blur" }
        ],
        keyword: [
          { required: true, message: "关键字不能为空", trigger: "blur" }
        ],
        barCode: [
          { required: true, message: "商品条码不能为空", trigger: "blur" }
        ],
        cateId: [
          { required: true, message: "分类id不能为空", trigger: "blur" }
        ],
        price: [
          { required: true, message: "商品价格不能为空", trigger: "blur" }
        ],
        vipPrice: [
          { required: true, message: "会员价格不能为空", trigger: "blur" }
        ],
        otPrice: [
          { required: true, message: "市场价不能为空", trigger: "blur" }
        ],
        postage: [
          { required: true, message: "邮费不能为空", trigger: "blur" }
        ],
        unitName: [
          { required: true, message: "单位名不能为空", trigger: "blur" }
        ],
        sort: [
          { required: true, message: "排序不能为空", trigger: "blur" }
        ],
        sales: [
          { required: true, message: "销量不能为空", trigger: "blur" }
        ],
        stock: [
          { required: true, message: "库存不能为空", trigger: "blur" }
        ],
        isShow: [
          { required: true, message: "状态不能为空", trigger: "blur" }
        ],
        isHot: [
          { required: true, message: "是否热卖不能为空", trigger: "blur" }
        ],
        isBenefit: [
          { required: true, message: "是否优惠不能为空", trigger: "blur" }
        ],
        isBest: [
          { required: true, message: "是否精品不能为空", trigger: "blur" }
        ],
        isNew: [
          { required: true, message: "是否新品不能为空", trigger: "blur" }
        ],
        addTime: [
          { required: true, message: "添加时间不能为空", trigger: "blur" }
        ],
        isPostage: [
          { required: true, message: "是否包邮不能为空", trigger: "blur" }
        ],
        isDel: [
          { required: true, message: "是否删除不能为空", trigger: "blur" }
        ],
        merUse: [
          { required: true, message: "商户是否代理 0不可代理1可代理不能为空", trigger: "blur" }
        ],
        cost: [
          { required: true, message: "成本价不能为空", trigger: "blur" }
        ],
        isSeckill: [
          { required: true, message: "秒杀状态 0 未开启 1已开启不能为空", trigger: "blur" }
        ],
        isGood: [
          { required: true, message: "是否优品推荐不能为空", trigger: "blur" }
        ],
        isSub: [
          { required: true, message: "是否单独分佣不能为空", trigger: "blur" }
        ],
        codePath: [
          { required: true, message: "商品二维码地址(用户小程序海报)不能为空", trigger: "blur" }
        ],
        videoLink: [
          { required: true, message: "主图视频链接不能为空", trigger: "blur" }
        ],
        tempId: [
          { required: true, message: "运费模板ID不能为空", trigger: "blur" }
        ],
        specType: [
          { required: true, message: "规格 0单 1多不能为空", trigger: "change" }
        ],
        activity: [
          { required: true, message: "活动显示排序0=默认, 1=秒杀，2=砍价，3=拼团不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商品管理列表 */
    getList() {
      this.loading = true;
      listProduct(this.queryParams).then(response => {
        this.productList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        merId: undefined,
        image: undefined,
        sliderImage: undefined,
        storeName: undefined,
        storeInfo: undefined,
        keyword: undefined,
        barCode: undefined,
        cateId: undefined,
        price: undefined,
        vipPrice: undefined,
        otPrice: undefined,
        postage: undefined,
        unitName: undefined,
        sort: undefined,
        sales: undefined,
        stock: undefined,
        isShow: undefined,
        isHot: undefined,
        isBenefit: undefined,
        isBest: undefined,
        isNew: undefined,
        addTime: undefined,
        isPostage: undefined,
        isDel: undefined,
        merUse: undefined,
        giveIntegral: undefined,
        cost: undefined,
        isSeckill: undefined,
        isBargain: undefined,
        isGood: undefined,
        isSub: undefined,
        ficti: undefined,
        browse: undefined,
        codePath: undefined,
        soureLink: undefined,
        videoLink: undefined,
        tempId: undefined,
        specType: undefined,
        activity: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商品管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getProduct(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改商品管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateProduct(this.form).then(response => {
              this.buttonLoading = false;
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProduct(this.form).then(response => {
              this.buttonLoading = false;
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除商品管理编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.loading = true;
          return delProduct(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有商品管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportProduct(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
